package com.asiainfo.complier.helper;

import java.util.Calendar;
import java.util.Date;

public class StringHelper {
	/**
	 * isNullOrEmpty
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isNullOrEmpty(String str) {
		return (str == null) || (str.length() == 0);
	}

	/**
	 * toDateString
	 * 
	 * @param date
	 * @return
	 */

	public static String toDateString() {
		return toDateString(-1);
	}

	/**
	 * toDateString
	 * 
	 * @param date
	 * @return
	 */
	public static String toDateString(long date) {

		Calendar calendar = Calendar.getInstance();
		if (date > 0) {
			Date time = new Date(date);
			calendar.setTime(time);
		}

		int year = Integer.valueOf(calendar.get(Calendar.YEAR));
		int month = Integer.valueOf(calendar.get(Calendar.MONTH) + 1);
		int day = Integer.valueOf(calendar.get(Calendar.DAY_OF_MONTH));
		int hour = Integer.valueOf(calendar.get(Calendar.HOUR_OF_DAY));
		int minute = Integer.valueOf(calendar.get(Calendar.MINUTE));
		int second = Integer.valueOf(calendar.get(Calendar.SECOND));

		return String.format("%s-%s-%s %s:%s:%s", new Object[] { year + "",
				month < 10 ? "0" + month : month, day < 10 ? "0" + day : day,
				hour < 10 ? "0" + hour : hour,
				minute < 10 ? "0" + minute : minute,
				second < 10 ? "0" + second : second

		});
	}

	private StringHelper() {
	}

}
